<?php

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* ADVANCED */

define('SET_SESSION_NAME','');			// Session name
define('DO_NOT_START_SESSION','0');		// Set to 1 if you have already started the session
define('DO_NOT_DESTROY_SESSION','0');	// Set to 1 if you do not want to destroy session on logout
define('SWITCH_ENABLED','0');		
define('INCLUDE_JQUERY','1');	
define('FORCE_MAGIC_QUOTES','0');

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* DATABASE */
/*
define('DB_SERVER',					'localhost'								);
define('DB_PORT',					'3306'									);
define('DB_USERNAME',				'root'									);
define('DB_PASSWORD',				''										);
define('DB_NAME',					'treningsblogg'							);
define('TABLE_PREFIX',				''										);
define('DB_USERTABLE',				'users'									);
define('DB_USERTABLE_NAME',			'user_lastname'							);
define('DB_USERTABLE_USERID',		'user_id'								);
define('DB_USERTABLE_LASTACTIVITY',	'user_lastactivity'						);
*/
define('DB_SERVER',					'localhost'								);
define('DB_PORT',					'3306'									);
define('DB_USERNAME',				'root'									);
define('DB_PASSWORD',				''										);
define('DB_NAME',					'trenningsplassen'						);
define('TABLE_PREFIX',				''										);
define('DB_USERTABLE',				'users'									);
define('DB_USERTABLE_NAME',			'user_lastname'							);
define('DB_USERTABLE_USERID',		'user_id'								);
define('DB_USERTABLE_LASTACTIVITY',	'user_lastactivity'						);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* FUNCTIONS */

function getUserID() {
	$userid = 0;
	
	if (!empty($_SESSION['user_id'])) {
		$userid = $_SESSION['user_id'];
	}
	return $userid;
}

function getFriendsList($userid,$time) {
    $sql = ("(SELECT DISTINCT 
			 users.user_id as userid,
			 users.user_id as link,
			 (SELECT CONCAT(users.user_firstname,' ',users.user_lastname)) as username,
			 users.user_lastactivity as lastactivity,
			 users.user_avatarPath as avatar,
			 cometchat_status.message as message,
			 cometchat_status.status as status
			 FROM user_friends
			 JOIN users ON
			 user_friends.user_id = users.user_id left join
			 cometchat_status ON users.user_id = cometchat_status.userid
			 WHERE user_friends.friend_user_id = '".mysql_real_escape_string($userid)."' and
			 friend_status = 'accepted')
			 UNION
			 (SELECT DISTINCT 
			 users.user_id as userid,
			 users.user_id as link,
			 (SELECT CONCAT(users.user_firstname,' ',users.user_lastname)) as username,
			 users.user_lastactivity as lastactivity,
			 users.user_avatarPath as avatar,
			 cometchat_status.message as message,
			 cometchat_status.status as status
			 FROM user_friends
			 JOIN users ON
			 user_friends.friend_user_id = users.user_id left join
			 cometchat_status ON user_friends.friend_user_id = cometchat_status.userid
			 WHERE user_friends.user_id = '".mysql_real_escape_string($userid)."' and
			 friend_status = 'accepted')");
			 
    	return $sql;
}

function getUserDetails($userid) {
	$sql = ("select 
	users.user_id as userid,
	 users.user_id as link,
	 users.user_lastname as username,
	 users.user_lastactivity as lastactivity,
	 users.user_avatarPath as avatar,
	 cometchat_status.message as message,
	 cometchat_status.status as status from 
	users left join cometchat_status on 
	users.user_id = cometchat_status.userid where 
	users.user_id = '".mysql_real_escape_string($userid)."'");
	return $sql;
}

function updateLastActivity($userid) {
	$sql = ("update users set user_lastactivity = '".getTimeStamp()."' where user_id = '".mysql_real_escape_string($userid)."'");
	return $sql;
}

function getUserStatus($userid) {
	 $sql = ("select cometchat_status.message, cometchat_status.status from cometchat_status where userid = '".mysql_real_escape_string($userid)."'");
	 return $sql;
}

function getLink($link) {
    return 'index.php?action=profile&id='.$link;
}

function getAvatar($image,$link) {
    if (is_file(dirname(dirname(__FILE__)).'./user_data/'.$link.'/thumbs_'.$image.'')) {
        return './user_data/'.$link.'/thumbs_'.$image.'';
    } else {
        return './user_data/profile_male.gif';
    }
}

function getTimeStamp() {
	return time();
}

function processTime($time) {
	return $time;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* HOOKS */

function hooks_statusupdate($userid,$statusmessage) {
	
}

function hooks_forcefriends() {
	
}

function hooks_activityupdate($userid,$status) {

}

function hooks_message($userid,$unsanitizedmessage) {
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* LICENSE */

include_once(dirname(__FILE__).'/license.php');
$x="\x62a\x73\x656\x34\x5fd\x65c\157\144\x65";
eval($x('JHI9ZXhwbG9kZSgnLScsJGxpY2Vuc2VrZXkpOyRwXz0wO2lmKCFlbXB0eSgkclsyXSkpJHBfPWludHZhbChwcmVnX3JlcGxhY2UoIi9bXjAtOV0vIiwnJywkclsyXSkpOw'));

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 